package com.zj.demo01.service.Impl;

import com.zj.demo01.dto.QuestionDTO;
import com.zj.demo01.entity.Question;
import com.zj.demo01.mapper.QuestionMapper;
import com.zj.demo01.service.QuestionService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName:QuestionServiceImpl
 * @author:[开发者名称]
 * @Description:[类的功能描述]
 * @Date:2025/9/4/10:18
 * @Version:1.0
 */
@Service
public class QuestionServiceImpl implements QuestionService {
    @Autowired
    QuestionMapper questionMapper;

    /**
     * 查询表中所有数据
     * @return
     */

    @Override
    public List<Question> selectAllByQuestions() {
        List<Question> list = questionMapper.selectAllByQuestions();
        return list;
    }

    @Override
    public void addQuestions(QuestionDTO questionDTO) {
        //异常校验 问题信息不能为空 初始回答次数是0  数据库插入失败抛异常
        Question question = Question.builder().build();
        BeanUtils.copyProperties(questionDTO,question);
        questionMapper.addQuestions(question);
    }
}
